package com.example;

import com.example.dao.StudentDao;
import com.example.dao.TeacherDao;
import com.example.entity.*;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;

@RunWith(SpringRunner.class)
@SpringBootTest(properties = {"spring.jpa.properties.hibernate.format_sql=true"},webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
public class Demo1 {

	@Autowired
	private TeacherDao teacherDao;

	@Autowired
	private StudentDao studentDao;


	@Test
	public void contextLoads() {

		List<Teacher> list = new ArrayList<>();

		Teacher teacher1 = new Teacher();
		teacher1.setName("李白");
		list.add(teacher1);

		Teacher teacher2 = new Teacher();
		teacher2.setName("孟浩然");
		list.add(teacher2);

		Teacher teacher3 = new Teacher();
		teacher3.setName("李清照");
		list.add(teacher3);

		teacherDao.save(list);
	}


	@Test
	public void student() {
		//创建Student实体
		Student s = new Student();
		s.setName("刘德华");
		s.setBirthday(LocalDate.of(1964,3,7));

		StudentInfo info = new StudentInfo();
		info.setStudent(s);
		info.setAddress(new Address("北京","酒仙桥中路26号","100001"));


		Classroom classroom = new Classroom();
		classroom.setId(1l);


		s.setClassroom(classroom);
		s.setInfo(info);


		studentDao.save(s);
	}

}
